from typing import Optional
from app.core.crud import CRUDBase
from app.models.storage import StorageConfig
from app.schemas.storage import StorageConfigCreate, StorageConfigUpdate

class StorageConfigController(CRUDBase[StorageConfig, StorageConfigCreate, StorageConfigUpdate]):
    def __init__(self):
        super().__init__(model=StorageConfig)

    async def get_config(self) -> Optional[StorageConfig]:
        """获取存储配置"""
        return await self.model.first()

    async def create_or_update(self, obj_in: StorageConfigCreate) -> StorageConfig:
        """创建或更新存储配置"""
        storage_config = await self.get_config()
        if storage_config:
            return await self.update(id=storage_config.id, obj_in=obj_in)
        return await self.create(obj_in=obj_in)

storage_config_controller = StorageConfigController() 